package com.zzyl.config;

import cn.hutool.json.JSONUtil;
import com.zzyl.service.ResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;

@Slf4j
@Configuration
public class ConfigInit implements InitializingBean {
    @Autowired
    private ResourceService resourceService;
    @Autowired
    private StringRedisTemplate redisTemplate;


    @Override
    public void afterPropertiesSet() throws Exception {
        //当启动springboot时将全部的按钮路径查询出来
        List<String> allButList = resourceService.findAllButResource();
        //将查询后的所有按钮路径存入redis
        redisTemplate.opsForValue().set("resource:allurls", JSONUtil.toJsonStr(allButList));
    }
}
